package com.wjk.cms.util.sms;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class AliyunSmsUtil {

    public static String sendSms(String signName, String phone, String code) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4G8MDLnqUw8uNzsJbYQ4", "B24Wj3EqNM2H5cV0MZpIkvuakpXwKz");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", phone);
        request.putQueryParameter("SignName", signName);
        request.putQueryParameter("TemplateCode", "SMS_149423642");
        request.putQueryParameter("TemplateParam", "{\"code\":\"" + code + "\"}");
        try {
            return client.getCommonResponse(request).getData();
        } catch (ClientException e) {
            log.error("发送短信失败 - " + e.getMessage(), e);
        }
        return null;
    }

}
